﻿using Biz.Core;
using Biz.Core.Models;
using Microsoft.AspNetCore.Mvc;
using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform;
using MiniFox.Resources;
using MiniFox.Utility;
using MiniFox.Web.Infrastructure;
using System.ComponentModel.DataAnnotations;

namespace Biz.WebApi.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [NoCache, PublicAccessible]
    public class OrderController : MvcControllerBase
    {
        /// <summary>
        /// 自动装载服务组件
        /// </summary>
        [AutoWired]
        public IOrderService OrderService { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderDto"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<OrderVo> Create([FromBody] OrderDto orderDto)
        {
            var result = this.OrderService.CreateOrder(orderDto);
            return result.CreateResponse();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderDto"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<OrderVo> Update([FromBody] OrderDto orderDto)
        {
            var result = this.OrderService.UpdateOrder(orderDto);
            return result.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<string> Delete([FromBody] string orderId)
        {
            var result = this.OrderService.DeleteOrder(orderId);
            return result.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<OrderVo> Pay([FromBody] string orderId)
        {
            OrderVo result = this.OrderService.OrderPay(orderId);
            return result.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [HttpGet]
        public Response<OrderVo> Get([FromQuery, Required(ErrorMessageResourceType = typeof(CommonMessages), ErrorMessageResourceName = "MSG_CommonRequired")] string orderId)
        {
            OrderVo result = this.OrderService.GetOrder(orderId);
            return result.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="queryObject"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<ResultObject<IEnumerable<OrderVo>>> Query([FromBody] PagedQueryObject<OrderSearchModel> queryObject)
        {
            var result = this.OrderService.QueryOrderList(queryObject);
            return result.CreateResponse();
        }
    }
}
